home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / MAG10.ZIP / FIRE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-14  |  5.0 KB  |  120 lines

  1. Program Fire;
  2.  
  3. { This code was TOTALLY developped by Ricardo M. Oliveira aka Scorpio,
  4.   having in thought the various approaches known to this effect...
  5.   Altough the code was totally developped by Scorpio, Spellcaster cleaned
  6.   it up a little and made it compatible with previous 'The Mag' issues.
  7.   This MAY NOT (and I do not intend it to be) the BEST one or the FASTEST
  8.   one... It is incredibly slow, too... It is even slower because Spellcaster
  9.   tweaked it to work with the Mode13h Unit... That is f#$%&% slow !!! :)
  10.   Its purpose is merely to show how it's done.
  11.     This source MAY be ripped in EVERY way known to man... The ONLY thing I
  12.   ask for is that you PLZ greet me in your demo/intro/whatever... If you have
  13.   questions, feel free to email me...
  14.   Email:
  15.         o questions:      si17899@ci.uminho.pt
  16.         o flames:         logname@hostname     :)
  17.  
  18.   Homepage:
  19.         o htpp://wwwalu.ci.uminho.pt:8888/~si17899
  20. }
  21.  
  22. Uses Crt,Mode13h;
  23.  
  24. { Needed 'coz of KEYPRESSED only... Don't have time to cut 'n' paste
  25.   from my utils unit... Maybe next time... }
  26.  
  27. Var Pal:RGBList;
  28.     Average:Byte; { ????? :) }
  29.     X,Y:Integer;  { Vars needed in the loops below }
  30.     Seed:Byte;
  31.  
  32. Procedure Hot_Spots;
  33. { Produces the hotspots of the bottom line of the fire with a random colour... }
  34. Var I,C1,C2:Integer;
  35. Begin
  36.      For I:=1 To 100 Do     { Why 100? This could be any number... This one
  37.                               just looks good... It is the number of hot_spots
  38.                               to set. }
  39.      Begin
  40.           C1:=Random(255);  { Random color to put in each hot spot. }
  41.           PutPixel(70+random(180),100,c1,VGA);
  42.           { WHAT ??? Why 100 ? And why from 70+random(180) ???
  43.             To speed things up a little, the fire starts at X=70 and ends
  44.             at X=250 and goes from Y=100 to Y=40... }
  45.      End;
  46. End;
  47.  
  48. Begin
  49.      Randomize;
  50.      InitGraph;
  51.      LoadPal('FIRE.PAL',Pal);
  52.      SetPalette(Pal);
  53.      Hot_Spots;
  54.      Repeat
  55.            Y:=100;
  56.            Repeat
  57.              For X:=70 To 250 Do
  58.              Begin
  59.                   { Get the average from the sum of the point we're
  60.                     calculating... Let's see... This is it:
  61.  
  62.                +       X is the point we're calculating...
  63.               +X+      We add the value from the three +'s and from
  64.                        the X itself and div by 4 ?!?!... :-)
  65.                                                                    }
  66.                   average:= (GetPixel(X-1,Y,VGA)+
  67.                              GetPixel(X,Y,VGA)+
  68.                              GetPixel(X+1,Y,VGA)+
  69.                              GetPixel(X,Y-1,VGA)) Div 4;
  70.  
  71.                   If Y>75 Then
  72.  
  73. { Ok... The next part may be a bit confusing... We have two different effects
  74.   here: The effect that takes place BELOW y=75 and the one that takes place
  75.   ABOVE y=75... If you look at the fire, you'll see that at a certain height
  76.   it starts to spread itself... That is the second effect...
  77.   Try to change the effects (one in the place of the other, or one of them
  78.   in the whole flame to see the differences... This is just a question of
  79.   playing with random numbers and the placement of the result for each pixel...
  80.   Below is another one, that is commented... try it. Just uncoment it and
  81.   comment the original... }
  82.  
  83.                     If Average>8 Then PutPixel(X,Y-1,Average-1,VGA)
  84.                     Else PutPixel(X,Y-1,Average,VGA)
  85.                   Else
  86.                     If Average>8 Then PutPixel(X+Random(3)-1,Y-1,Average-1,VGA)
  87.                     Else PutPixel(X-1,Y-1,Average,VGA);
  88.  
  89.                   { Strong wind from the right :)        }
  90.                   { If Average>8 Then PutPixel(X+Random(2)-1,Y-1,Average-1,VGA)
  91.                     Else PutPixel(X+Random(2)-1,Y-1,Average,VGA);  }
  92.  
  93.              End;
  94.            Dec(Y,1);
  95.            Until Y=40; { As I have said before, I am trying to speed this up
  96.                          and keep the code easy to understand... The fire also
  97.                          goes from line 100 (base) to line 40 (top of the fire) }
  98.  
  99.       Hot_Spots;
  100.       Until KeyPressed;
  101.       CloseGraph;
  102.  
  103.       { These are my greetz... in NO PARTICULAR ORDER other than the one my
  104.         confusing mind gave me. }
  105.  
  106.         TextColor(LightGray);
  107.         WriteLn('The old fire routine, one more time... ');
  108.         Write('By: ');
  109.         TextColor(LightBlue); Write('Ricardo M. Oliveira ');
  110.         TextColor(LightGray); Write('aka');
  111.         TextColor(Yellow); WriteLn(' Scorpio');
  112.         TextColor(LightGray); write('Email: ');
  113.         TextColor(White); Writeln('si17899@ci.uminho.pt');
  114.         TextColor(LightGray); Writeln('Greetz go to:');
  115.         TextColor(White);
  116.         Writeln('Spellcaster, Cpt Hook, DUF and RD members, NSJ, Virtual Fantasies members,');
  117.         Writeln('everybody from LESI (You know who you are), Virus and Jony_Bigodes :))),');
  118.         Writeln('and *everybody* in Moosaico at University of Minho.');
  119. End.
  120.